const { notEmpty } = require('../utils.js')

module.exports = {
    description: '生成一个组件模板',
    prompts: [
        {
            type: 'input',
            name: 'name',
            message: '请输入组件名称',
            validate: notEmpty('name')
        },
        {
            type: 'checkbox',
            name: 'blocks',
            message: '组成：',
            choices: [
                {
                    name: '<template>',
                    value: 'template',
                    checked: true
                },
                {
                    name: '<script>',
                    value: 'script',
                    checked: true
                },
                {
                    name: '<style>',
                    value: 'style',
                    checked: true
                }
            ],
            validate(value) {
                if (value.indexOf('script') === -1 && value.indexOf('template') === -1) {
                    return '请至少选择一个template作为模板，或者使用script中render函数来渲染'
                }
                return true
            }
        }
    ],
    actions: data => {
        const name = '{{properCase name}}'
        const actions = [{
            type: 'add',
            path: `src/components/${name}/index.vue`,
            templateFile: 'plop-templates/component/index.hbs',
            data: {
                name,
                template: data.blocks.includes('template'),
                script: data.blocks.includes('script'),
                style: data.blocks.includes('style')
            }
        }]
        return actions
    }
}